import { getHotSearch, getSearchList } from "@/services";

const state = {
  hotSearchList: [],
  searchList: [],
};

const mutations = {
  getHotSearch(state, payload) {
    state.hotSearchList = payload.result;
  },
  getSearchList(state, payload) {
    state.searchList = payload.searchList;
  },
};

const actions = {
  // 获取数据热门搜索
  async getHotSearch({ commit }) {
    let result = await getHotSearch();
    commit("getHotSearch", { hotSearchList:result.records });
  },
  // 获取搜索商品列表
  async getSearchList({ commit }, data) {
    let result = await getSearchList(data);
    commit("getSearchList", { searchList: result.records });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
